﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Pages_PoApproval : System.Web.UI.Page
{

    #region Page Load
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BLL_tbl_purchase_order bll = new BLL_tbl_purchase_order();
            DataTable dt = bll.FetchPendingApproval();
            if (dt != null)
            {
                if (dt.Rows.Count > 0)
                {
                    grdPoOrder.DataSource = dt;
                    grdPoOrder.DataBind();
                }
            }
        }
    }
    #endregion

    #region Gridview Row Command
    protected void gridMembersList_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Accept")
        {
            
            //int index = Convert.ToInt32(e.CommandArgument.ToString());
           // GridViewRow grow = grdPoOrder.Rows[Convert.ToInt32(e.CommandArgument.ToString())];
            GridViewRow grow = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
            if (grow != null)
            {
                BLL_tbl_purchase_order bll = new BLL_tbl_purchase_order();
                try
                {
                    bll.appprovePo(Int32.Parse(grow.Cells[0].Text),User.Identity.Name);
                    DataTable dt = bll.FetchPendingApproval();
                    if (dt != null)
                    {
                        if (dt.Rows.Count > 0)
                        {
                            grdPoOrder.DataSource = dt;
                            grdPoOrder.DataBind();
                        }
                        else
                        {
                            grdPoOrder.DataSource = null;
                            grdPoOrder.DataBind();
                        }
                    }
                    else
                    {
                        grdPoOrder.DataSource = null;
                        grdPoOrder.DataBind();
                    }

                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Success", "alert('Order Accepted Succesfully');", true);
                    return;
                }
                catch
                {
                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Error", "alert('Error Occured while Approval');", true);
                    return;
                
                }
            }
          
        }
    }
    #endregion

}